﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using SysFrame.BP;
using SysFrame.Message;

namespace AppServer.Controllers.System
{
    [Route("api/[controller]")]
    [ApiController]
    public class System8Controller : SysControllerBase
    {
        //功能
        // POST: api/System6
        [HttpPost]
        public ActionResult<string> Post([FromBody] dynamic data)
        {
            string jsTimeStamp = data.jsTimeStamp;
            string Action = data.Action == null ? "Get" : data.Action;
            string rtstr = "";
            if (Action == "Get")
            {
                rtstr = Get(data);
            }
            if (Action == "Save")
            {
                rtstr = Save(data);
            }
            return rtstr;
        }

        /// <summary>
        /// 得到按钮列表
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Get(dynamic data) {
            MsQuery msq = new MsQuery();
            //msq.strquery += " and SYSTEM_8_40 ='" + row["SYSTEM_7_30"].ToString() + "'";
            msq.strquery += " and 1=1 and (SYSTEM_8_50='1' or SYSTEM_8_50 is null) ";
            msq.strorder = " SYSTEM_8_60 ";//排序语句
            List<Mssystem_8> listms = new BLLsystem_8().Getsystem_8MsByQuery(msq);
            return JArray.FromObject(listms).ToString();
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public string Save(dynamic data)
        {
            JObject postdata = JObject.FromObject(data.data);
            Mssystem_8 ms8 = Mssystem_8.parse<Mssystem_8>(postdata);
            ms8.System_8_50 = "1";
            MsReturned rt = new BLLsystem_8().Savesystem_8(ms8);
            return JObject.FromObject(rt).ToString();
        }
    }
}
